package com.bj58.data.hadoop.info.tools;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 */

/**
 * @author Administrator
 * 
 */
public class RowKeyCombination {

	
	public static List<String> zuHe(List<String> combList,Integer count)
	{
		List<String> result = new ArrayList<String>();
		Object[] dimensionArray = combList.toArray();
		if(count == 1)
		{
			for(int leftIndex=dimensionArray.length-1;leftIndex>=0;leftIndex--)
			{
				result.add(dimensionArray[leftIndex].toString());
			}
		}
		else
		{
			for(int leftIndex=0;leftIndex<=dimensionArray.length-1;leftIndex++)
			{
				String fixKey = dimensionArray[leftIndex].toString();
				List<String> rawList = new ArrayList<String>();
				for(int rawleft = leftIndex+1;rawleft<=dimensionArray.length-1;rawleft++)
				{
					rawList.add(dimensionArray[rawleft].toString());
				}
				List<String> tempList = zuHe(rawList,count-1);
				for(String temp:tempList)
				{
					result.add(fixKey+"###"+temp);
				}
			}
		}
		return result;
	}
	
	
	public static void main(String[] args) {
		
		List<String> dimensionList = new ArrayList<String>();
		
		dimensionList.add("cates:A");
		dimensionList.add("areaf:A");
		dimensionList.add("pagetype:A");
		dimensionList.add("os:A");
		dimensionList.add("cversion:A");
		dimensionList.add("channelid:A");
		
		for(int i=1;i<=6;i++)
		{
			List<String> result = RowKeyCombination.zuHe(dimensionList, i);
			int count = Integer.parseInt("2"+ i + "001");
			for(String rowKey:result)
			{
				System.out.println("stat_id:"+count++);
				System.out.println(rowKey+"\r");
			}
		}
		
	}
}
